define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'study/rebook/index' + location.search,
                    add_url: 'study/rebook/add',
                    edit_url: 'study/rebook/edit',
                    del_url: 'study/rebook/del',
                    multi_url: 'study/rebook/multi',
                    table: 'study',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        //{field: 'user_id', title: __('User_id')},
                        //{field: 'class_id', title: __('Class_id')},
                        {field: 'study_title', title: __('Study_title')},
                        //{field: 'author_id', title: __('Author_id')},
                        //{field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'weigh', title: __('Weigh')},
                        //{field: 'city', title: __('City')},
                        //{field: 'address', title: __('Address')},
                        //{field: 'date', title: __('Date'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'name', title: __('Name')},
                        //{field: 'vip_video', title: __('Vip_video')},
                        //{field: 'user_video', title: __('User_video')},
                        {field: 'time', title: __('Time')},
                        //{field: 'introduce', title: __('简介')},
                        //{field: 'vip_price', title: __('Vip_price'), operate:'BETWEEN'},
                        //{field: 'market_price', title: __('Market_price'), operate:'BETWEEN'},
                        {field: 'browse', title: __('Browse')},
                        //{field: 'like', title: __('Like')},
                        //{field: 'favorite', title: __('Favorite')},
                        //{field: 'is_good', title: __('Is_good'), searchList: {"0":__('Is_good 0'),"1":__('Is_good 1')}, formatter: Table.api.formatter.normal},
                        //{field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1')}, formatter: Table.api.formatter.normal},
                        {field: 'is_exquisite', title: __('Is_exquisite'), searchList: {"0":__('Is_exquisite 0'),"1":__('Is_exquisite 1')}, formatter: Table.api.formatter.normal},
                        //{field: 'is_week', title: __('Is_week'), searchList: {"0":__('Is_week 0'),"1":__('Is_week 1')}, formatter: Table.api.formatter.normal},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'studyclass.id', title: __('Studyclass.id')},
                        {field: 'studyclass.class_name', title: __('Studyclass.class_name')},
                        //{field: 'studyclass.pid', title: __('Studyclass.pid')},
                        //{field: 'studyclass.createtime', title: __('Studyclass.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'studyclass.updatetime', title: __('Studyclass.updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'studyclass.deletetime', title: __('Studyclass.deletetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'studyauthor.id', title: __('Studyauthor.id')},
                        {field: 'studyauthor.author', title: __('Studyauthor.author')},
                        //{field: 'studyauthor.author_identity', title: __('Studyauthor.author_identity')},
                        //{field: 'studyauthor.type', title: __('Studyauthor.type')},
                        //{field: 'studyauthor.create_time', title: __('Studyauthor.create_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});